﻿@model Product

<h3 style="color:red;">Quản Lý Sản Phẩm</h3>
<br/>

<div role="tabpanel">

    <!-- Nav tabs -->
    <ul class="nav nav-tabs" role="tablist">
        <li role="presentation" class="active"><a href="#edit" aria-controls="edit" role="tab" data-toggle="tab">Thêm Sản Phẩm &nbsp;<span class="glyphicon glyphicon-star"></span></a></li>
        <li role="presentation"><a href="#list" aria-controls="list" role="tab" data-toggle="tab">Danh Sách Sản Phẩm &nbsp;<span class="glyphicon glyphicon-star-empty"></span></a></li>
    </ul>

    <!-- Tab panes -->
    <div class="tab-content">
        <div role="tabpanel" class="tab-pane active" id="edit">
            <h4>@Html.ValidationSummary(true)</h4>
            @Html.AntiForgeryToken()
            @using (Html.BeginForm("Insert", "Product",
    FormMethod.Post, new { enctype = "multipart/form-data" }))
            {
                @Html.HiddenFor(s => s.Id)
                <div class="row">
                   
                    <div class="form-group col-md-4">
                        <div>Tên Sản Phẩm</div>
                        @Html.TextBoxFor(s => s.Name, new { @class = "form-control" })
                    </div>

                    <div class="form-group col-md-4">
                        <div>Giá Sản phẩm</div>
                        @Html.TextBoxFor(s => s.UnitPrice, new { @class = "form-control" })
                    </div>

                    <div class="form-group col-md-4">
                        <div>Khuyến Mãi</div>
                        @Html.TextBoxFor(s => s.UnitBrief, new { @class = "form-control" })
                    </div>
                </div>

                <div class="row">
                    <div class="form-group col-md-4">
                        <div>Số Lượng</div>
                        @Html.TextBoxFor(s => s.Quantity, new { @class = "form-control" })
                    </div>

                    <div class="form-group col-md-4">
                        <div>Giảm Giá</div>
                        @Html.TextBoxFor(s => s.Discount, new { @class = "form-control" })
                    </div>

                    <div class="form-group col-md-4">
                        <div>Ngày Sản Xuất</div>
                        @Html.TextBoxFor(s => s.ProductDate, "{0:MM/dd/yyyy}", new { @class = "form-control datepicker" })
                    </div>
                </div>

                <div class="row">
                    <div class="form-group col-md-4">
                        <div>Sản Phẩm Mới</div>
                        @Html.CheckBoxFor(s => s.Latest)
                    </div>

                    <div class="form-group col-md-4">
                        <div>Sản Phẩm Đặc Biệt</div>
                        @Html.CheckBoxFor(s => s.Special)
                    </div>

                    <div class="form-group col-md-4">
                        <div>Đang Kinh Doanh</div>
                        @Html.CheckBoxFor(s => s.Available)
                    </div>
                </div>

                <div class="row">
                    <div class="form-group col-md-4">
                        <div>Hình Ảnh</div>
                        <input type="file" name="UpImage" />
                        @Html.HiddenFor(s => s.Image)
                    </div>

                    <div class="form-group col-md-4">
                        <div>Chủ Đề Sản Phẩm</div>
                        @Html.DropDownList("CategoryId", null, new { @class = "form-control" })
                    </div>

                    <div class="form-group col-md-4">
                        <div>Nhà Cung Cấp</div>
                        @Html.DropDownList("SupplierId", null, new { @class = "form-control" })
                    </div>
                </div>

                <div class="row">
                    <div class="form-group col-md-12">
                        <div>Mô Tả</div>
                        @Html.TextAreaFor(s => s.Description, new { rows = 5, @class = "form-control" })
                        <script type="text/javascript">
                            CKEDITOR.replace("Description")
                        </script>
                    </div>
                </div>

                <div class="row">
                    <div class="form-group col-md-12">
                        <div></div>
                        <div>
                            <button onclick="form.action='/Admin/Product/Insert'" class="btn btn-default">Insert</button>
                            @if (Model.Id != 0)
                            {
                                <button onclick="form.action='/Admin/Product/Update' " class="btn btn-default">Update</button>
                                <a href="/Admin/Product/Delete/@Model.Id" onclick="return Xoa();" class="btn btn-default">Delete</a>
                            }
                            <a href="/Admin/Product/Index" class="btn btn-default">Reset</a>
                        </div>
                    </div>
                </div>
            }
        </div>
        <div role="tabpanel" class="tab-pane" id="list">
            <br/><br/>
            <div id="tablePro"></div>
            <div>
                <ul class="pager">
                    <li><a href="pageNo=0">First</a></li>
                    <li><a href="pageNo-=1">Prev</a></li>
                    <li><span id="pageNo"></span>&nbsp;<span>@ViewBag.PageCount</span></li>
                    <li><a href="pageNo+=1">Next</a></li>
                    <li><a href="pageNo=pageCount-1">Last</a></li>
                </ul>
            </div>
        </div>
    </div>

</div>



@section scripts{
<script src="~/jquery-ui/jquery-ui.min.js"></script>
<link href="~/jquery-ui/jquery-ui.min.css" rel="stylesheet" />>
    <script>
        $(function () {
            $("input.datepicker").datepicker();
        });
    </script>

<script>
        $(function () {
            pageNo = 0;
            pageCount = @ViewBag.PageCount
            fnLoadPage();

            $("ul.pager a").click(function () {
                eval($(this).attr("href"));
                fnLoadPage();
                return false;
            });
        });

        function fnLoadPage() {
            if (pageNo < 0) {
                pageNo = pageCount - 1;
            }
            if (pageNo >= pageCount) {
                pageNo = 0;
            }
            $.ajax({
                url: "/Admin/Product/GetPage",
                data: { pageNo: pageNo },
                success: function (response) {
                    $("#tablePro").html(response);
                }
            });
            $("#pageNo").html(pageNo + 1);
        }
</script>

<script>
    function Xoa() {
        var ok = confirm("Có chắc chắn xóa mẫu tin có mã  không?");
        if (ok == true) {
            window.location.href = "/Admin/Product/Delete/@Model.Id";
        } else {
            return false;
        }
    }
</script>


}

